package org.training.apr.service.mapper.impl;


import java.util.ArrayList;
import java.util.List;

import org.dozer.DozerBeanMapper;
import org.training.apr.dto.UserDto;
import org.training.apr.model.User;
import org.training.apr.service.mapper.Mapper;

public class DozerMapper implements Mapper {
	protected static final DozerBeanMapper mapper = new DozerBeanMapper();
	
	public DozerMapper() {
		List<String> mappingFiles = new ArrayList<String>();
		mappingFiles.add("dozer-system-wide-configuration.xml");
		
		mapper.setMappingFiles(mappingFiles);
	}

	public UserDto toDto(User user) {
		return (UserDto) map(user, UserDto.class);
	}

	private Object map(Object source, Class<?> aClass) {
		if(source == null) {
			return null;
		}
		return mapper.map(source, aClass);
	}
}
